package com.lyf.learn.atsgg.spring.ioc;

import com.alibaba.druid.pool.DruidDataSource;
import com.lyf.learn.atsgg.spring.ioc.bean.CollectionBean;
import com.lyf.learn.atsgg.spring.ioc.bean.ListStyleBean;
import com.lyf.learn.atsgg.spring.ioc.bean.UserBean;
import com.lyf.learn.atsgg.spring.ioc.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.util.Arrays;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/24
 * @VERSION 1.0
 * @DESC
 */
public class IocMain {
    public static void main(String[] args) {
        String path1 = "beans\\UserBean.xml";
        String path2 = "beans\\AccountBean.xml";
        String path3 = "beans\\Beans.xml";
        String path4 = "beans\\ListStyleBean.xml";
        String path5 = "beans\\AutowireBean.xml";
        ApplicationContext applicationContext =new ClassPathXmlApplicationContext(path5);//path1,path2,path3,path4
//        String[]beans = applicationContext.getBeanDefinitionNames();
//        for(String bean:beans){
//            System.out.println(bean);
//        }
//        UserBean user1 = (UserBean) applicationContext.getBean("user1");
//        user1.call();
//        UserService userService= (UserService) applicationContext.getBean("userService");
//        userService.add();
//        CollectionBean collectionBean=applicationContext.getBean("Col2",CollectionBean.class);
//        collectionBean.print();

//        ListStyleBean l =applicationContext.getBean("bean1", ListStyleBean.class);
//        System.out.println(l.getName());
//
//        DataSource dataSource = new DruidDataSource();

        System.out.println("扫描的组件:");
        System.out.println(Arrays.toString(applicationContext.getBeanDefinitionNames()));
    }
}
